<?php


namespace App\Http\Controllers\Forwarder;


use App\Http\Controllers\Controller;
use App\Models\ForwarderLineCost;
use App\Models\ForwarderLineCostOther;
use Illuminate\Http\Request;

class ForwarderLineCostController extends Controller
{

    public function index(Request $request)
    {
        $cost = ForwarderLineCost::where('forwarder_line_id', $request->input('forwarder_line_id'))->get();
        $costOther1 = ForwarderLineCostOther::where('forwarder_line_id', $request->input('forwarder_line_id'))->where('type',0)->get();
        $costOther2 = ForwarderLineCostOther::where('forwarder_line_id', $request->input('forwarder_line_id'))->where('type',1)->get();
        return $this->response(compact('cost','costOther1','costOther2'));
    }

    public function view($id, Request $request){
        $obj = ForwarderLineCost::where('id',$id)->where('forwarder_line_id', $request->input('forwarder_line_id'))->first();
        return $this->response($obj);
    }

    public function store(Request $request, ForwarderLineCost $obj)
    {
        $all = $request->all();
        $obj->fill($all);
        $obj->forwarder_line_id = $request->input('forwarder_line_id');
        $obj->save();
        return $this->response($obj->id);
    }

    public function update($id, Request $request)
    {
        $obj = ForwarderLineCost::where('id',$id)->where('forwarder_line_id', $request->input('forwarder_line_id'))->first();
        $obj->update($request->all());
        return $this->response();
    }

    public function destroy($id)
    {
        $obj = ForwarderLineCost::find($id);
        $obj->delete();
        return $this->response();
    }

}
